package com.android.jingweiapp.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.jingweiapp.R;
import com.android.jingweiapp.fragment.InformationFragment;
import com.android.jingweiapp.fragment.InterctFragment;
import com.android.jingweiapp.fragment.PublicInfoFragment;
import com.android.jingweiapp.fragment.TopicFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    @Bind(R.id.ly_container)
    FrameLayout lyContainer;
    @Bind(R.id.tv_one)
    TextView tvOne;
    @Bind(R.id.tv_two)
    TextView tvTwo;
    @Bind(R.id.tv_three)
    TextView tvThree;
    @Bind(R.id.tv_four)
    TextView tvFour;

    private InformationFragment informationFragment;
    private InterctFragment interctFragment;
    private PublicInfoFragment publicInfoFragment;
    private TopicFragment topicFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        init();
    }

    private void init() {
        informationFragment = new InformationFragment();
        interctFragment = new InterctFragment();
        publicInfoFragment = new PublicInfoFragment();
        topicFragment = new TopicFragment();

        getSupportFragmentManager().beginTransaction()
                .add(R.id.ly_container, topicFragment).hide(topicFragment)
                .add(R.id.ly_container, publicInfoFragment).hide(publicInfoFragment)
                .add(R.id.ly_container, interctFragment).hide(interctFragment)
                .add(R.id.ly_container, informationFragment).hide(informationFragment)
                .commit();

        tvOne.setSelected(true);
        tvOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .show(informationFragment)
                        .hide(publicInfoFragment)
                        .hide(interctFragment)
                        .hide(topicFragment).commit();
                tvOne.setSelected(true);
                tvTwo.setSelected(false);
                tvThree.setSelected(false);
                tvFour.setSelected(false);
            }
        });

        tvTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .show(publicInfoFragment)
                        .hide(topicFragment)
                        .hide(interctFragment)
                        .hide(informationFragment).commit();
                tvOne.setSelected(false);
                tvTwo.setSelected(true);
                tvThree.setSelected(false);
                tvFour.setSelected(false);
            }
        });

        tvThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .show(interctFragment)
                        .hide(publicInfoFragment)
                        .hide(informationFragment)
                        .hide(topicFragment).commit();
                tvOne.setSelected(false);
                tvTwo.setSelected(false);
                tvThree.setSelected(true);
                tvFour.setSelected(false);

            }
        });

        tvFour.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getSupportFragmentManager().beginTransaction()
                        .show(topicFragment)
                        .hide(publicInfoFragment)
                        .hide(interctFragment)
                        .hide(informationFragment).commit();
                tvOne.setSelected(false);
                tvTwo.setSelected(false);
                tvThree.setSelected(false);
                tvFour.setSelected(true);
            }
        });

        tvOne.callOnClick();

    }

}
